03 / 19

Explain the concept of Amortized O(1) for Dynamic Array insertion.

Amortized Analysis

javascript
  1. 1

    An individual resize can be O(n).

  2. 2

    Resizing happens only occasionally when capacity is exhausted.

  3. 3

    Geometric growth prevents resizing on every insertion.

  4. 4

    Across n insertions, total copying work is O(n).

  5. 5

    Therefore, append is amortized O(1), although its worst-case individual operation can be O(n).

Difficulty: 3/10

Follow-up Questions

  • What is the difference between amortized and average-case complexity?
  • Why is geometric growth important?